from collections import OrderedDict
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


class MyPagination(PageNumberPagination):
    page_size = 5
    max_page_size = 20
    page_size_query_param = 'pagesize'
    page_query_param = 'pagenum'
    def get_paginated_response(self, data):
        return Response(OrderedDict([
            ('count', self.page.paginator.count),#数据记录总条数
            ('pagenum', self.page.number),#当前的页码
            ('total_page', self.page.paginator.num_pages),#总页数
            ('data', data),#当前页展示的数据
            ('status', 200)
        ]))